package cn.legend.travel.guide.util;

import cn.legend.travel.guide.pojo.entity.User;
import cn.legend.travel.guide.pojo.po.GuidePO;
import cn.legend.travel.guide.pojo.vo.GuideVO;
import org.springframework.beans.BeanUtils;

import java.util.*;

public class GuidePOListToMapConvertor {
    public static List<Map<String, Object>> convert(List<GuidePO> guideList){

        List<Map<String, Object>> list = new ArrayList<>();
        if(guideList.isEmpty()){
            return null;
        }
        for (GuidePO guidePO : guideList) {
            Map<String, Object> map = new HashMap<>();
            GuideVO guideVO = new GuideVO();
            BeanUtils.copyProperties(guidePO,guideVO);
            switch (guidePO.getType()){
                case 0:
                    map.put("type","美食");
                    break;
                case 1:
                    map.put("type","景点");
                    break;
                case 2:
                    map.put("type","城市");
                    break;
                case 3:
                    map.put("type","酒店");
                    break;
                default:
                    map.put("type","其他");
                    break;
            }
            User user = new User();
            user.setId(guidePO.getAuthorId());
            user.setNickName(guidePO.getUsername());
            user.setImgUrl(guidePO.getAvatar());
            map.put("coverUrl",guidePO.getCoverUrl());
            map.put("title",guidePO.getTitle());
            map.put("brief",guidePO.getBrief());
            map.put("viewCount",guidePO.getViewCount());
            map.put("likeCount",guidePO.getLikeCount());
            map.put("commentCount",guidePO.getCommentCount());
            map.put("user",user);
            list.add(map);
        }

        return list;
    }
}
